package nn;

import java.util.ArrayList;

import nn.config.Config;
import nn.config.FalceIconsConfig;
import nn.config.FalceIconsConfigBias;
import nn.config.IconsConfig;
import nn.config.XorConfig;
import nn.networks.BPNetwork;
import nn.phraseparameters.BPPhraseParameters;

public class BPNetworkTest {
	public static void main(String[] args) throws Exception {

		System.out.println("start");

		BPNetwork net = new BPNetwork();
		Config config;
		config = new IconsConfig();
		config = new FalceIconsConfig();
		config = new FalceIconsConfigBias();
		 config = new XorConfig();
//		config = new EvenProblemConfig();

		String path = config.getPath();
		ArrayList<float[]> inputsList = config.getInputsList();
		ArrayList<float[]> outputsList = config.getOutputsList();
		net.readConfFile(path);
net.printNetwork();
		ArrayList<BPPhraseParameters> phraseParList = new ArrayList<>();
		float learningSpeed = (float) 0.9;
		float momentum = (float) 0.6;
		// even
//		learningSpeed = (float) 0.5;
//		momentum = (float) 0.2;
		// xor
		 learningSpeed = (float) 0.4;
		 momentum = (float) 0.8;

		phraseParList.add(new BPPhraseParameters(5000, learningSpeed, momentum));
		phraseParList.add(new BPPhraseParameters(10000, learningSpeed / 2, momentum / 2));
//		phraseParList.add(new BPPhraseParameters(40000, learningSpeed / 4, momentum / 4));
		// phraseParList.add(new BPPhraseParameters(5000, learningSpeed,
		// momentum));
		// phraseParList.add(new BPPhraseParameters(6000, learningSpeed / 2,
		// momentum / 2));
		// phraseParList.add(new BPPhraseParameters(8000, learningSpeed / 4,
		// momentum / 4));

		// phraseParList.add(new BPPhraseParameters(8000, learningSpeed,
		// momentum));
		// phraseParList.add(new BPPhraseParameters(16000, learningSpeed / 2,
		// momentum / 2));
		// phraseParList.add(new BPPhraseParameters(24000, learningSpeed / 4,
		// momentum / 4));
		// phraseParList.add(new BPPhraseParameters(32000, learningSpeed / 8,
		// momentum / 8));

		// Learning
		net.epochLearn(phraseParList, inputsList, outputsList);
		net.printNetwork();

		// printing result
		System.out.println();
		float[] result;
		for (int i = 0; i < config.getSize(); ++i) {
			result = net.calculate(inputsList.get(i));
			String stringRes = config.getOutputIcons().get(i) + " ->";

			for (int j = 0; j < result.length; ++j) {
				stringRes = stringRes + ", " + result[j];
			}
			System.out.println(stringRes);
		}

	}
}
